<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>出租单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">

<!-- 查询条件开始-->
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" method="post" id="searchFrm">
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">出租单号:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="rentid"   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">身份证号:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="identity"     autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">车牌号:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="carnumber"   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="startTime" id="startTime" readonly="readonly"   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束时间:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="endTime" id="endTime"  readonly="readonly"  autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">归还状态:</label>
                        <div class="layui-input-inline">
                            <select name="rentflag">
                                <option value="">请选择状态</option>
                                <option value="1">已归还</option>
                                <option value="0">未归还</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div  class="layui-form-item" style="text-align: center;">
                <div class="layui-input-block" >
                    <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" lay-submit lay-filter="doSearch">查询</button>
                    <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
                </div>
            </div>
        </form>
    </blockquote>
</form>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="carTable" lay-filter="carTable"></table>

    <script id="carRowBar"  type="text/html">


            {{#  if(d.rentflag==1){ }}

            {{#  } else { }}
            <button type="button" lay-event="renCar" class="layui-btn  layui-btn-xs">
                <span class="layui-icon layui-icon-edit"></span>更新
            </button>

            {{#  } }}



        <button type="button" lay-event="viewRent" class="layui-btn layui-btn-xs">
            <span class="layui-icon layui-icon-search"></span>查看
        </button>
    </script>
</div>
<!-- 数据表格结束 -->

<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="addOrUpdateDiv" >

    <form class="layui-form layui-row layui-col-space10"  lay-filter="dataFrm" id="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <!-- 隐藏域 -->
                <input type="hidden" name="id">

                <div class="layui-col-md8 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车牌号:</label>
                        <div class="layui-input-block">
                            <input type="text" name="carnumber" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车辆类型:</label>
                        <div class="layui-input-block">
                            <input type="text" name="cartype" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">租车时间:</label>
                        <div class="layui-input-block">
                            <input type="text" name="begindate" id="rentdate" class="layui-input" readonly lay-verify="required" placeholder="请选择租车时间">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4 layui-col-xs5">
                    <div class="layui-upload-list thumbBox mag0 magt3" id="carimgDiv">
                        <!-- 显示上传的图片 -->
                        <img class="layui-upload-img thumbImg" id="showCarImg" src="/file/showImages/images/defaultimg.jpg">
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">身份证号码:</label>
                <div class="layui-input-block">
                    <input type="text" name="identity"  class="layui-input" lay-verify="required" placeholder="请输入身份证号码">
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">租赁天数:</label>
                    <div class="layui-input-block">
                        <input type="text" name="rentday" id="rentday" class="layui-input" lay-verify="required|number" placeholder="请输入租赁天数">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出租价格:</label>
                    <!-- 租金 -->
                    <input type="hidden" name="rentprice" id="rentprice">
                    <div class="layui-input-block">
                        <input type="text" name="price" id="totalPrice" class="layui-input" lay-verify="required|number" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;text-align: center;">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release" lay-filter="doSubmit" lay-submit="">提交</button>
                    <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm layui-icon layui-icon-refresh" >重置</button>
                </div>
            </div>
        </div>
    </form>

</div>
<!--查看出租单详情-->
<div id="viewRentDiv" style="display: none;padding: 20px">
    <form class="layui-form layui-row layui-col-space10" lay-filter="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md8 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车牌号:</label>
                        <div class="layui-input-block">
                            <input type="text" name="carnumber" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">车辆类型:</label>
                        <div class="layui-input-block">
                            <input type="text" name="cartype" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">租车时间:</label>
                        <div class="layui-input-block">
                            <input type="text" name="begindate" id="s_rentdate" class="layui-input" readonly lay-verify="required" >
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4 layui-col-xs5">
                    <div class="layui-upload-list thumbBox mag0 magt3">
                        <!-- 显示上传的图片 -->
                        <img class="layui-upload-img thumbImg" id="s_showCarImg" src="/file/showImages/images/defaultimg.jpg">
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">身份证号码:</label>
                <div class="layui-input-block">
                    <input type="text" name="identity"  class="layui-input"readonly>
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">租赁天数:</label>
                    <div class="layui-input-block">
                        <input type="text" name="rentday" id="s_rentday" class="layui-input" readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出租价格:</label>
                    <div class="layui-input-block">
                        <input type="text" name="price" id="s_totalPrice" class="layui-input"  readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">还车时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="returndate" id="s_returndate" class="layui-input"  readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">操作人:</label>
                    <div class="layui-input-block">
                        <input type="text" name="opername" id="s_opername" class="layui-input"  readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0" style="margin-top:20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">创建时间:</label>
                    <div class="layui-input-block">
                        <input type="text" name="createtime" id="s_createtime" class="layui-input"  readonly>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">归还状态:</label>
                    <div class="layui-input-block">
                        <input type="text" name="rentflag" id="s_rentflag" class="layui-input"  readonly>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<!-- 添加和修改的弹出层结束 -->


<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        var  laydate=layui.laydate;

        //初始化时间选择器
        laydate.render({
            elem:'#startTime',//绑定渲染的元素
            type:'datetime'
        });
        laydate.render({
            elem:'#endTime',//绑定渲染的元素
            type:'datetime'
        });

        var tableIns = table.render({
            elem: '#carTable'
            ,url:'/bus/rent/list'
            ,toolbar: '#carToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,page: true
            ,height:"full-180"
            ,title: '出租单数据表'
            ,cols: [ [
                {field:'id', title:'编号',align:'center',width:'80'}
                ,{field:'rentid', title:'出租单号',align:'center',width:'280'}
                ,{field:'carnumber', title:'车牌号',align:'center',width:'120'}
                ,{field:'price', title:'出租价格',align:'center',width:'120'}
                ,{field:'rentflag', title:'归还状态',align:'center',width:'120',templet:function(d){
                        return d.rentflag=='1'?'<font color=blue>已归还</font>':'<font color=red>未归还</font>';
                    }}
                ,{field:'begindate', title:'出租时间',align:'center',width:'200'}
                ,{field:'returndate', title:'归还时间',align:'center',width:'200'}
                ,{field:'rentday', title:'租赁天数',align:'center',width:'100'}
                ,{fixed: 'right', title:'操作', toolbar: '#carRowBar', width:220,align:'center'}
            ] ],
            done:function (res,curr,count) {
                //判断当前页码是否是大于1并且当前页的数据量为0
                if(curr>1 && res.data.length==0){
                    var pageValue = curr -1;
                    //刷新数据表格的数据
                    tableIns.reload({
                        page:{curr:pageValue}
                    });
                }
            }
        });

        //监听表单提交事件（模糊查询）
        form.on("submit(doSearch)",function (data) {
            tableIns.reload({
                url:'/bus/rent/list',
                where:data.field,
                page:{
                    curr:1
                }
            });
            return false;
        });





        //监听行工具栏事件
        table.on('tool(carTable)',function (obj) {
            switch (obj.event) {
                case 'renCar':
                    //打开头部工具栏添加公告的窗口
                    openUpdateRentWindow(obj.data);
                    break;
                case 'viewRent':
                    viewRentInfo(obj.data); //查看出租单信息
                    break
            }
        })





        var mainIndex;//打开窗口的索引
        var url;//提交请求的地址




        /**
         * 更新出租
         */
        function openUpdateRentWindow(data) {
            mainIndex =layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:["800px","550px"],
                title:"更新车辆",
                success:function () {
                    //表单数据回显
                    form.val("dataFrm",data);
                    //提交请求
                    url = "/bus/rent/updateRent";
                    //查询汽车相关的数据
                    $.get("/bus/car/getCarInfoByCarnumber",{"carnumber":data.carnumber},function(result){
                        //赋值
                        $("#rentprice").val(result.rentprice);//租车单价
                        $("[name='cartype']").val(result.cartype);//车辆类型
                        $("#showCarImg").attr("src","/file/showImages/"+result.carimg);//车辆图片
                    },"json");
                }
            });
        }


        /**
         * 查看大图
         * @param data
         */
      function viewRentInfo(data){
            mainIndex= layer.open({
                type:1,
                content:$('#viewRentDiv'),
                area:["800px","500px"],
                title:"【"+data.carnumber+'】的出租单信息',
                success:function (index) {
                  form.val("dataFrm",data);//回显
                  //查询出租价格
                    $.get("/bus/car/getCarInfoByCarnumber", {"carnumber":data.carnumber}, function (result) {
                        $("#rentprice").val(result.rentprice);//租车单价
                        $("[name='cartype']").val(result.cartype);//车辆类型
                        $("#showCarImg").attr("src","/file/showImages/"+result.carimg);//车辆图片
                    }, "json");
                    if(data.rentflag==1){
                        $("#s_rentflag").val("已归还");
                    }else{
                        $("#s_rentflag").val("未归还");
                    }
                }

            })

      }

      //租赁天数失去焦点时,计算价格天数乘以单价
        $("#rentday").blur(function () {
            //获取天数
            var day=$(this).val();
            if (day.length!=0){
                //汽车租金
                var rentprice=$("#rentprice").val();
                //总金额
                $("#totalPrice").val(day * rentprice);
            }else {
                $("#totalPrice").val("");
            }
        })


        //监听表单提交事件
        form.on("submit(doSubmit)",function (data) {
            $.post(url, data.field, function (result) {
                if (result.success){
                    //提示信息
                    layer.msg(result.message,{icon:1})

                    tableIns.reload();

                    layer.close(mainIndex);

                }else {
                    layer.msg(result.message,{icon:2});
                }
            }, "json");
            //禁止页面跳转
            return false;
        })



    });


</script>



</body>
</html>